package com.whli.autumn.mall.web.controller.wms;

import com.github.pagehelper.PageInfo;
import com.whli.autumn.core.app.annotation.ApiVersion;
import com.whli.autumn.core.extend.controller.BaseController;
import com.whli.autumn.core.permission.annotation.RequirePermissions;
import com.whli.autumn.core.share.ResponseResult;
import com.whli.autumn.mall.wms.domain.dto.StockActionDTO;
import com.whli.autumn.mall.wms.domain.dto.stock.StockPageDTO;
import com.whli.autumn.mall.wms.domain.entity.Stock;
import com.whli.autumn.mall.wms.manage.StockActionManage;
import com.whli.autumn.mall.wms.service.IStockService;
import com.whli.autumn.mall.wms.domain.vo.stock.StockVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>库存信息API</p>
 *
 * @author whli
 * @version 1.0.0
 * @since 2023-04-09 08:37
 */
@Api(tags = "仓库管理-库存信息")
@ApiVersion
@RestController
@RequestMapping(value = "/wms/stock")
public class StockController extends BaseController<Stock, IStockService> {

    @Autowired
    private StockActionManage stockActionManage;

    /**
     * <p>分页查询库存信息</p>
     *
     * @author  whli
     * @since   2023-04-09 08:37
     * @param   entity 分页参数
     * @return
     */
    @ApiOperation(value = "分页查询库存信息", httpMethod = "GET")
    @RequirePermissions("wms:stock:list")
    @GetMapping("page")
    public ResponseResult<PageInfo<StockVO>> listByPage(StockPageDTO entity) {
        PageInfo<StockVO> page = service.listByPage(entity);
        return ResponseResult.success(page);
    }

    @ApiOperation(value = "入库", httpMethod = "POST")
    @RequirePermissions("user")
    @PostMapping("in")
    public ResponseResult<String> inStock(@RequestBody StockActionDTO entity) {
        int rows = stockActionManage.inStock(entity);
        return rows > 0 ? ResponseResult.success("入库成功") : ResponseResult.fail("入库失败");
    }

    @ApiOperation(value = "出库", httpMethod = "POST")
    @RequirePermissions("user")
    @PostMapping("out")
    public ResponseResult<String> outStock(@RequestBody StockActionDTO entity) {
        int rows = stockActionManage.outStockAndNotVerifyOccupancy(entity);
        return rows > 0 ? ResponseResult.success("出库成功") : ResponseResult.fail("出库失败");
    }

}
